<template>
  <div class="app-container">
    <el-form
      :model="memberGradeConfig"
      :rules="rules"
      ref="memberGradeConfig"
      label-position="right"
      label-width="120px" style="margin-left:30px;"
    >
      <el-row :gutter="24" style="margin-bottom: 60px;">
        <div>
          <span>会员年度经验值递减配置</span>
          <el-divider></el-divider>
        </div>
        <el-form-item label="注册会员经验值" prop="grade1">
          <el-input-number v-model="memberGradeConfig.grade1" :min="0" :max="0" :precision="0"></el-input-number>
          <span class="form-word-hint">注册会员经验值默认为0，不能编辑</span>
        </el-form-item>
        <el-form-item label="铜牌会员经验值" prop="grade2">
          <el-input-number v-model="memberGradeConfig.grade2" :min="0" :max="999999999" :precision="0"></el-input-number>
          <span class="form-word-hint">注册会员年度减少经验值</span>
        </el-form-item>
        <el-form-item label="银牌会员经验值" prop="grade3">
          <el-input-number v-model="memberGradeConfig.grade3" :min="0" :max="999999999" :precision="0"></el-input-number>
          <span class="form-word-hint">铜牌会员年度减少经验值</span>
        </el-form-item>
        <el-form-item label="金牌会员经验值" prop="grade4">
          <el-input-number v-model="memberGradeConfig.grade4" :min="0" :max="999999999" :precision="0"></el-input-number>
          <span class="form-word-hint">银牌会员年度减少经验值</span>
        </el-form-item>
        <el-form-item label="钻石会员经验值" prop="grade5">
          <el-input-number v-model="memberGradeConfig.grade5" :min="0" :max="999999999" :precision="0"></el-input-number>
          <span class="form-word-hint">金牌会员年度减少经验值</span>
        </el-form-item>
        <el-form-item>
          <span class="form-word-hint">年度减少经验值：会员注册日起，每年会减少会员的累计经验值，从而影响会员的等级。</span>
        </el-form-item>
      </el-row>

      <el-row :gutter="24">
        <div class="fixed-bottom-20">
            <el-button type="primary" @click="submitForm('memberGradeConfig')">立即提交</el-button>
        </div>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { Message } from 'element-ui'
import { gradedownMember, gradedownUpdateMember} from '@/api/member'
export default {
  name: "gradeconfigedit",
  data() {
    return {
      memberGradeConfig: {},
      rules: {
        grade1: [{ required: true, message: '请填写注册会员经验值', trigger: 'blur' }],
        grade2: [{ required: true, message: '请填写铜牌会员经验值', trigger: 'blur' }],
        grade3: [{ required: true, message: '请填写银牌会员经验值', trigger: 'blur' }],
        grade4: [{ required: true, message: '请填写金牌会员经验值', trigger: 'blur' }],
        grade5: [{ required: true, message: '请填写钻石会员经验值', trigger: 'blur' }]
      },
    };
  },
  created() {
    gradedownMember().then((res) => {
      this.memberGradeConfig = res.data.data.memberGradeConfig
    })
  },
  methods: {
    submitForm(memberGradeConfig) {
      this.$refs[memberGradeConfig].validate((valid) => {
        if (valid) {
          gradedownUpdateMember(this.memberGradeConfig).then(res => {
            if(!res.data.success) {
              Message.error(res.data.message);
              return;
            }
            Message.success('操作成功')
            return;
          })
        }
      });
    }
  }

}
</script>

<style>
</style>
